import React, { useState } from "react";
import { Form, Input, Button } from "antd-mobile";
import { loginDataType } from "../../interface";
import { apiLogin } from "../../api";
import Cookie from "js-cookie";
import "./style.scss";

const Login = () => {

  const onFinish = (data: loginDataType) => {
    apiLogin(data).then((res: any) => {
      //保存到本地
      Cookie.set("token", res.token);
      window.location.href = "/home/shouye";
    });
  };

  return (
    <div>
      <h1>欢迎，</h1>
      <p>欢迎来到宏烨找房</p>
      <Form name="basic" onFinish={onFinish}>
        <Form.Item
          label="账户"
          name="username"
          rules={[{ required: true, message: "请输入账户" }]}
        >
          <Input placeholder='请输入账户'/>
        </Form.Item>

        <Form.Item
          label="密码"
          name="password"
          rules={[{ required: true, message: "请输入密码" }]}
        >
          <Input placeholder="请输入密码"/>
        </Form.Item>

        <Form.Item>
          <Button block type='submit' color='primary' size='large'>
            登录
          </Button>
        </Form.Item>

      </Form>
    </div>
  );
};
export default Login;
